package Login;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.Timer;
 

public class MainPane extends JPanel  implements MouseListener, MouseMotionListener, ActionListener{
	private CardLayout cards;
	private int curFrame;
	private JPanel parent;
	private Button login, cancel, um;
	private BufferedImage bg, bg2, bg3, bg4, bg5, bgCur, nisoft;
	private Timer time; 
	
	public MainPane(JPanel parent, int n, CardLayout cards){
		this.cards=cards;
		this.curFrame=n;
		this.parent=parent;

		login = new Button("images/login.png","images/login2.png","images/login3.png");  
		cancel =new Button("images/cancel.png","images/cancel2.png","images/cancel3.png"); 
		um = new Button("images/um.png","images/um2.png","images/um3.png");
		 
		try {
			bg= ImageIO.read(new File("images/bgyel.png"));
			bg2= ImageIO.read(new File("images/bggreen.png"));
			bg3= ImageIO.read(new File("images/bgred.png"));
			bg4= ImageIO.read(new File("images/bgpurp.png"));
			bg5= ImageIO.read(new File("images/bg.jpg"));
			nisoft = ImageIO.read(new File("images/NISOFT.png"));
			
				
		} catch (IOException e) {
			System.out.print("Image not found");
			e.printStackTrace();
		}
		bgCur =  bg;
		
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		parent.setPreferredSize(this.getDimension());
		
		time = new Timer(300, this);
		
	}
	
	public Dimension getDimension(){
		
		return new Dimension(bg.getWidth()+15, bg.getHeight()+38);
	}

	@Override
	public void actionPerformed(ActionEvent m) {
		// TODO Auto-generated method stub
		repaint();
	}
	
	public void paint(Graphics g){
		time.start();
		super.paint(g);
		Graphics2D g2D = (Graphics2D) g;
		g2D.drawImage(bgCur, 0, 0, null);

		g2D.drawImage(nisoft, 75, 105, null);
		g2D.drawImage(login.getCurImg(), 75, 225, null);
		g2D.drawImage(cancel.getCurImg(), 290, 225, null);
		g2D.drawImage(um.getCurImg(), 175, 300, null);
		
	}
	@Override
	public void mouseDragged(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent m) {
		// TODO Auto-generated method stub
		if (m.getX() >= 75&& m.getX()<=215&&m.getY()>=225&&m.getY()<=275){//within the boundaries of login btn
			bgCur=bg2;
			login.setCurImg(1);
			 

		}
		else if(m.getX()>=290&&m.getX()<=430&&m.getY()>=225&&m.getY()<=275){//within the boundaries of cancel btn
			bgCur=bg3;
			cancel.setCurImg(1);
			
			 
		}
		else if(m.getX()>=175&&m.getX()<=315&&m.getY()>=300&&m.getY()<=350){//within the boundaries of um btn
			bgCur=bg4;	 
			um.setCurImg(1);
		}
		else{

			login.setCurImg(0);
			cancel.setCurImg(0);
			um.setCurImg(0);
			bgCur=bg;	
			
		}
	}

	@Override
	public void mouseClicked(MouseEvent m) {
		// TODO Auto-generated method stub
		if (m.getX() >= 75&& m.getX()<=215&&m.getY()>=225&&m.getY()<=275){

			cards.show(parent, curFrame+1+"");
			

		}
		if(m.getX()>=290&&m.getX()<=430&&m.getY()>=225&&m.getY()<=275)	
			System.exit(0);
		
	}

	@Override
	public void mouseEntered(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent m) {
		// TODO Auto-generated method stub
		bgCur=bg5;
		login.setCurImg(2);
		cancel.setCurImg(2);
		um.setCurImg(2);
	}

	@Override
	public void mousePressed(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	
}
